﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;
namespace DAO
{
    public class Thuoc_DAO
    {
        public static DataTable DanhSachThuoc()
        {
            DataTable dt = DataProvider.SelectStoreProcedure("sp_DanhSachThuoc");
            return dt;
        }
        public static Boolean ThemThuoc(Thuoc_DTO ThuocDto)
        {
            List<SqlParameter> ParaArr = new List<SqlParameter>();
            string procname = "sp_ThemThuoc";
            ParaArr.Add(new SqlParameter("@TenThuoc", ThuocDto.TenThuoc));
            ParaArr.Add(new SqlParameter("@TinhTrang", ThuocDto.TinhTrang));
            ParaArr.Add(new SqlParameter("@Gia", ThuocDto.Gia));
            ParaArr.Add(new SqlParameter("@NgayHetHan ", ThuocDto.NgayHetHan));
            return DataProvider.NonqueryProc(procname, ParaArr);
        }

        public static Boolean CapNhatThuoc(Thuoc_DTO ThuocDto)
        {
            List<SqlParameter> ParaArr = new List<SqlParameter>();
            string procname = "sp_CapNhatThuoc";
            ParaArr.Add(new SqlParameter("@MaThuoc", ThuocDto.MaThuoc));
            ParaArr.Add(new SqlParameter("@TenThuoc", ThuocDto.TenThuoc));
            ParaArr.Add(new SqlParameter("@TinhTrang", ThuocDto.TinhTrang));
            ParaArr.Add(new SqlParameter("@Gia", ThuocDto.Gia));
            ParaArr.Add(new SqlParameter("@NgayHetHan ", ThuocDto.NgayHetHan));
            return DataProvider.NonqueryProc(procname, ParaArr);
        }

        public static Boolean XoaThuoc(string MaThuoc)
        {
            List<SqlParameter> ParaArr = new List<SqlParameter>();
            string procname = "sp_XoaThuoc";
            ParaArr.Add(new SqlParameter("@MaThuoc", MaThuoc));
            return DataProvider.NonqueryProc(procname, ParaArr);
        }

        public static DataTable DanhSachThuocTheoTen(string TenThuoc)
        {
            List<SqlParameter> ParaArr = new List<SqlParameter>();
            string procname = "sp_DanhSachThuocTheoTen";
            ParaArr.Add(new SqlParameter("@TenThuoc", TenThuoc));
            DataTable dt = DataProvider.SelectStoreProcedure(procname, ParaArr);
            return dt;
        }

        public static int KiemTraThuocTonTaiOut(string tenthuoc)
        {
            List<SqlParameter> ParaArr = new List<SqlParameter>();
            string procname = "KiemTraThuocTonTai";
            ParaArr.Add(new SqlParameter("@TenThuoc", tenthuoc));
            SqlParameter output = new SqlParameter("@ketqua", SqlDbType.NChar, 10);
            SqlCommand cmd = DataProvider.OutPutProc(procname, ParaArr, output);
            return int.Parse(cmd.Parameters["@ketqua"].Value.ToString());
        }
    }
}
